package com.itheima.blog.web.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.blog.util.BeanHelper;
import com.itheima.blog.util.UserThreadLocalUtils;

import com.itheima.blog.web.dao.TAlbumMapper;
import com.itheima.blog.web.domain.po.TAlbum;

import com.itheima.blog.web.service.ITAlbumService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户相册表 服务实现类
 * </p>
 *
 * @author wc
 * @since 2023-07-11
 */
@Service
public class TAlbumServiceImpl extends ServiceImpl<TAlbumMapper, TAlbum> implements ITAlbumService {

    @Override
    public String getImageUrl(Long id) {
        TAlbum album = this.getById(id);
       return album.getUrl();

    }
    @Override
    public PageResDto<TAlbum> showPages(PageReqDto pageReqDto) {
        Page<TAlbum> tAlbumPage = new Page<>();
        tAlbumPage.setSize(pageReqDto.getSize());
        tAlbumPage.setPages(pageReqDto.getPage());
        Page<TAlbum> page = lambdaQuery().eq(TAlbum::getUserId, UserThreadLocalUtils.getWebUserId())
                .page(tAlbumPage);
        List<TAlbum> records = page.getRecords();
        if (records.isEmpty()){
            return null;
        }
        List<TAlbum> tAlbums = BeanHelper.copyWithCollection(records, TAlbum.class);
        PageResDto<TAlbum> dto = new PageResDto<>(pageReqDto, page.getTotal(), tAlbums);
        return dto;
    }



}
